package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.PrivateMessage;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IPrivateMessageService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("privateMessages")
public class PrivateMessageController {
   @Autowired
   private IPrivateMessageService privateMessageService;
    @PostMapping("/{Uid}")
    public JSONResult save(@PathVariable Long Uid,PrivateMessage privateMessage){
        //保存信息的操作应该保存两次,因为对方有保存,接收方也有保存操作

        //发送方的保存操作
        privateMessage.setReceiverId(Uid);
        //朋友id
        privateMessage.setFriendId(Uid);
     /*   privateMessageService.saveSend(privateMessage);*/

        //收信人的操作操作
        privateMessage.setUserId(Uid);
        //还有朋友的id是当前登录的用户,在实现类中添加
        privateMessageService.saveReceiver(privateMessage);
        return new JSONResult();
    }
    @GetMapping
    public PrivateMessage queryOneForId(Long id){
        PrivateMessage privateMessage = privateMessageService.queryOneForId(id);
        return privateMessage;
    }
   @PutMapping("/{mid}")
    public JSONResult changeStatus(@PathVariable Long mid){
        privateMessageService.changeStatus(mid);
        return new JSONResult();
    }
    @DeleteMapping
    public JSONResult delete(Long id){
        privateMessageService.deleteLetter(id);
        return new JSONResult();//默认删除成功
    }

}
